const title = document.querySelector(".title");

let includeSpace = false;
const words = () => {
    const temp = title.textContent.trim().split(" ");
    if (temp.length > 1) {
        // 文本存在空格，说明为多个单词，则动画按单词设置
        includeSpace = true;
        return temp;
    } else {
        // 文本不存在空格，说明为单个单词或中文，则动画按单个字母设置
        includeSpace = false;
        return title.textContent.trim().split("");
    }
};

const wordsEls = words().map((item, index) => {
    return `<span style="--delay: ${index * 100}ms;" class="word"><i style="--delay: ${
        index * 100
    }ms;" class="letter">${item}</i></span>`;
});

title.innerHTML = includeSpace ? wordsEls.join(" ") : wordsEls.join("");

setInterval(function () {
    window.location.reload();
}, 5000);
